package com.txunda.zhuohired.aty.user.my;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.ants.theantsgo.gson.GsonUtil;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.adapter.user.my.BankTypeAdapter;
import com.txunda.zhuohired.base.BaseAty;
import com.txunda.zhuohired.bean.user.my.BankTypeBean;
import com.txunda.zhuohired.http.pst.InfoPst;

import java.util.ArrayList;
import java.util.List;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/3/8 15:01
 * 功能描述：选择银行卡类型
 * 联系方式：jiahuanchen@126.com
 */

public class BankTypeAty extends BaseAty {
    /**
     * 标题
     */
    @ViewInject(R.id.tv_layout_white_center)
    private TextView tv_layout_white_center;
    /**
     * listView
     */
    @ViewInject(R.id.lv_bank_type)
    private ListView lv_bank_type;

    private BankTypeAdapter bankTypeAdapter;

    private List<BankTypeBean.DataBean> bankNameList;
    private InfoPst infoPst;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        showStatusBar(R.id.layout_white_head);
        tv_layout_white_center.setText("选择银行卡类型");
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.aty_bank_type;
    }

    @Override
    protected void initialized() {
        infoPst = new InfoPst(this);
        bankNameList = new ArrayList<>();
    }

    @Override
    protected void requestData() {
        infoPst.supportBankList();
    }

    private void initAdapter() {
        bankTypeAdapter = new BankTypeAdapter(this, bankNameList);
        lv_bank_type.setAdapter(bankTypeAdapter);
        lv_bank_type.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent();
                intent.putExtra("bank_name", bankNameList.get(i).getBank_name());
                intent.putExtra("bank_id", bankNameList.get(i).getBank_id());
                setResult(RESULT_OK, intent);
                finish();
            }
        });
    }

    @Override
    public void onComplete(String requestUrl, String jsonStr) {
        super.onComplete(requestUrl, jsonStr);
        if(requestUrl.contains("supportBankList")){
            BankTypeBean bankTypeBean = GsonUtil.GsonToBean(jsonStr,BankTypeBean.class);
            bankNameList = bankTypeBean.getData();
            initAdapter();
            return;
        }
    }
}
